package jsyf.oa.web.wechat.service_account.controller;

import com.alibaba.fastjson.JSONObject;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.wechat.service_account.AnalyzeDataFacade;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/analyzeData")
public class AnalyzeDataController {

    @Resource
    private AnalyzeDataFacade analyzeDataFacade;

    //  获取用户增减数据
    @RequestMapping(value = "/getusersummary.json", method = RequestMethod.POST)
    public void getusersummary(HttpServletResponse response, @RequestBody String jsonData) {

        // 调用接口查询
        JSONObject jsonObject = analyzeDataFacade.getusersummary("2018-01-06", "2018-01-11");
        if (jsonObject != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(jsonObject));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    //  获取累计用户数据
    @RequestMapping(value = "/getusercumulate.json", method = RequestMethod.POST)
    public void getusercumulate(HttpServletResponse response, @RequestBody String jsonData) {

        // 调用接口查询
        JSONObject jsonObject = analyzeDataFacade.getusercumulate("2018-01-06", "2018-01-11");
        if (jsonObject != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjTimeRespond(jsonObject));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
}